import { calculateRowSpans } from '@/utils/util'
import { Image, Space, TableColumnsType, Tooltip, Typography } from 'antd'
import { PurchaseFabricOrderVO as ITableData, SupplierColorStockPageVO } from './types'
export const useFabricColumns = ({
  tableData,
}: {
  tableData: ITableData[]
}): TableColumnsType<SupplierColorStockPageVO> => {
  const firstSpan = calculateRowSpans(tableData || [], 'fabricCode', 'supplierName')
  return [
    {
      title: '面料编码',
      dataIndex: 'fabricCode',
      key: 'fabricCode',
      align: 'center',
      width: 130,
      onCell: (_, index) => {
        return { rowSpan: index != undefined ? firstSpan[index] : 0 }
      },
      render: (info) => {
        return info || '-'
      },
    },
    {
      title: '面料名称',
      dataIndex: 'fabricName',
      key: 'fabricName',
      align: 'center',
      width: 130,
      onCell: (_, index) => {
        return { rowSpan: index != undefined ? firstSpan[index] : 0 }
      },
      render: (info) => {
        return info || '-'
      },
    },
    {
      title: '面种编码',
      dataIndex: 'fabricTypeCode',
      key: 'fabricTypeCode',
      align: 'center',
      width: 100,
      onCell: (_, index) => {
        return { rowSpan: index != undefined ? firstSpan[index] : 0 }
      },
      render: (info) => {
        return info || '-'
      },
    },
    {
      title: '面料供应商',
      dataIndex: 'supplierName',
      key: 'supplierName',
      align: 'center',
      width: 200,
      onCell: (_, index) => {
        return { rowSpan: index != undefined ? firstSpan[index] : 0 }
      },
      ellipsis: {
        showTitle: false,
      },
      render: (info) => {
        return info ? <Tooltip title={info}>{info || '-'}</Tooltip> : '-'
      },
    },
    {
      title: '坯布下单量',
      dataIndex: 'baseFabricOrderQty',
      key: 'baseFabricOrderQty',
      align: 'center',
      width: 100,
      onCell: (_, index) => {
        return { rowSpan: index != undefined ? firstSpan[index] : 0 }
      },
      render: (info, rows) => {
        return info ? info + (rows?.fabricUnit || '') : '-'
      },
    },
    {
      title: '当前可用库存-坯布',
      dataIndex: 'currentBaseFabricStockQty',
      key: 'currentBaseFabricStockQty',
      align: 'center',
      width: 140,
      onCell: (_, index) => {
        return { rowSpan: index != undefined ? firstSpan[index] : 0 }
      },
      render: (info, rows) => {
        return (
          <span style={{ fontWeight: 800, color: 'var(--primary-color)' }}>
            {info ? info + (rows?.fabricUnit || '') : '-'}
          </span>
        )
      },
    },

    {
      title: '成品数量-坯布',
      dataIndex: 'currentBaseFabricFinishedQty',
      key: 'currentBaseFabricFinishedQty',
      align: 'center',
      width: 110,
      onCell: (_, index) => {
        return { rowSpan: index != undefined ? firstSpan[index] : 0 }
      },
      render: (info, rows) => {
        return info ? info + (rows?.fabricUnit || '') : '-'
      },
    },
    {
      title: '色布编码',
      dataIndex: 'colorFabricCode',
      key: 'colorFabricCode',
      align: 'center',
      width: 170,
      render: (info) => {
        return info ? info : '-'
      },
    },
    {
      title: '面料色',
      dataIndex: 'fabricColorDetailName',
      key: 'fabricColorDetailName',
      align: 'center',
      width: 100,
      render: (info) => {
        return info || '-'
      },
    },
    {
      title: '色布实际下单量',
      dataIndex: 'colorFabricOrderQty',
      key: 'colorFabricOrderQty',
      align: 'center',
      width: 120,
      render: (info, rows) => {
        return info ? info + (rows?.fabricUnit || '') : '-'
      },
    },
    {
      title: '当前可用库存-色布',
      dataIndex: 'currentColorFabricStockQty',
      key: 'currentColorFabricStockQty',
      align: 'center',
      width: 140,
      render: (info, rows) => {
        return (
          <span style={{ fontWeight: 800, color: 'var(--primary-color)' }}>
            {info ? info + (rows?.fabricUnit || '') : '-'}
          </span>
        )
      },
    },
    {
      title: '成品数量-色布',
      dataIndex: 'colorFabricFinishQty',
      key: 'colorFabricFinishQty',
      align: 'center',
      width: 110,
      render: (info, rows) => {
        return info ? info + (rows?.fabricUnit || '') : '-'
      },
    },
    {
      title: '实际交货量',
      dataIndex: 'actualQty',
      key: 'actualQty',
      align: 'center',
      width: 110,
      render: (info, rows) => {
        return info ? info + (rows?.fabricUnit || '') : '-'
      },
    },
  ]
}

export const useSupplierColumns = (): TableColumnsType<ITableData> => [
  {
    title: '成衣供应商',
    dataIndex: 'productSupplierName',
    key: 'productSupplierName',
    align: 'center',
    width: 200,
    ellipsis: {
      showTitle: false,
    },
    render: (info) => {
      return info ? <Tooltip title={info}>{info || '-'}</Tooltip> : '-'
    },
  },
  {
    title: '面料编码',
    dataIndex: 'fabricCode',
    key: 'fabricCode',
    align: 'center',
    width: 100,
    render: (info) => {
      return info || '-'
    },
  },
  {
    title: '面料名称',
    dataIndex: 'fabricName',
    key: 'fabricName',
    align: 'center',
    width: 100,
    render: (info) => {
      return info || '-'
    },
  },
  {
    title: '色布编码',
    dataIndex: 'colorFabricCode',
    key: 'colorFabricCode',
    align: 'center',
    width: 170,
    render: (info) => {
      return info ? info : '-'
    },
  },
  {
    title: '使用部位',
    dataIndex: 'useSite',
    key: 'useSite',
    align: 'center',
    width: 100,
    render: (info) => {
      return info || '-'
    },
  },
  {
    title: '面料色',
    dataIndex: 'fabricColorDetailName',
    key: 'fabricColorDetailName',
    align: 'center',
    width: 100,
    render: (info) => {
      return info || '-'
    },
  },
  {
    title: '面料供应商',
    dataIndex: 'supplierName',
    key: 'supplierName',
    align: 'center',
    fixed: 'left',
    width: 200,
    ellipsis: {
      showTitle: false,
    },
    render: (info) => {
      return info ? <Tooltip title={info}>{info || '-'}</Tooltip> : '-'
    },
  },
  {
    title: '色布实际下单量',
    dataIndex: 'colorFabricOrderQty',
    key: 'colorFabricOrderQty',
    align: 'center',
    width: 100,
    render: (info, rows) => {
      return info ? info + (rows?.fabricUnit || '') : '-'
    },
  },
  {
    title: '实际交货量',
    dataIndex: 'actualQty',
    key: 'actualQty',
    align: 'center',
    width: 100,
    render: (info, rows) => {
      return info ? info + (rows?.fabricUnit || '') : '-'
    },
  },
]
